package org.fast.easy.messages.controller;


import cn.hutool.core.util.RandomUtil;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.fast.easy.core.constant.Constants;
import org.fast.easy.core.constant.GlobalConstants;
import org.fast.easy.core.domain.result.R;
import org.fast.easy.framework.mail.config.properties.MailProperties;
import org.fast.easy.framework.mail.utils.MailUtils;
import org.fast.easy.framework.ratelimiter.annotation.RateLimiter;
import org.fast.easy.framework.redis.utils.RedisUtils;
import org.fast.easy.framework.web.core.BaseController;
import org.fast.easy.messages.service.IEmailService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;

/**
 * 邮件功能
 *
 * @author Lion Li
 */
@Slf4j
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/email")
public class SysEmailController extends BaseController {

    private final IEmailService emailService;

    /**
     * 邮箱验证码
     *
     * @param email 邮箱
     */
    @RateLimiter(key = "#email", time = 60, count = 1)
    @GetMapping("/code")
    public R<Void> emailCode(@NotBlank(message = "{user.email.not.blank}") String email) {

        return emailService.emailCode(email);
    }

}
